package com.holly.unit.bpmn.designer.core.strategy;

import com.holly.unit.bpmn.designer.constants.BpmnDesignerConstants;
import com.holly.unit.bpmn.designer.core.bpmn.BpmnModelFactory;
import com.holly.unit.bpmn.designer.enums.ApprovalModeEnum;
import com.holly.unit.bpmn.designer.model.ChildNode;
import com.holly.unit.bpmn.designer.model.TreeSelectModel;
import org.activiti.bpmn.model.UserTask;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 类描述: 指定角色 策略
 *
 * @author fxr
 * @version 1.0.0
 * @date 2022/5/13 9:13
 */
public class CreateCandidateGroupsTaskStrategy implements CreateTaskStrategy{

    @Override
    public UserTask createTask(ChildNode node, BpmnModelFactory factory) {

        List<TreeSelectModel> groups = node.getProperties().getApproverRoles();
        List<String> roleIds = groups.stream().map(TreeSelectModel::getId).collect(Collectors.toList());

        UserTask userTask = null;

        // 会签任务
        if (node.getProperties().getOptionalMultiUser().equals(ApprovalModeEnum.COUNTER_SIGN.fieldName())) {

            userTask = factory.createCountersignCandidateGroupsTask(node.getNodeId(),node.getProperties().getTitle(),
                    BpmnDesignerConstants.COUNTER_SIGN_ASSIGN_LIST,
                    BpmnDesignerConstants.COUNTER_SIGN_ASSIGNEE_NAME,
                    BpmnDesignerConstants.COUNTER_SIGN_COMPLTE_CONDITION,
                    BpmnDesignerConstants.COUNTER_SIGN_ASSIGNNAME,roleIds);
        } else if (node.getProperties().getOptionalMultiUser().equals(ApprovalModeEnum.OR_SIGN.fieldName())) {//或签任务
            userTask = factory.createCandidateGroupsTask(node.getNodeId(),node.getProperties().getTitle(),roleIds);
        } else if (node.getProperties().getOptionalMultiUser().equals(ApprovalModeEnum.NEXT_SIGN.fieldName())) {//顺序签
            // TODO 顺序签
        }

        return userTask;

    }

}
